import Head from 'next/head'
import Link from 'next/link'
import { readFile } from 'fs'
import { promisify } from 'util'
import { join } from 'path'

const read = promisify(readFile)

export default function List({data}) {
  return (
    <>
      <Head>
        <title>page list</title>
      </Head>
      <div>
        page list
        <Link href="/"><a>to page index</a></Link>
        <div>{data}</div>
      </div>
    </>
  )
}

// getServerSideProps getStaticProps
export async function getServerSideProps (context) {
  console.log(context.query)
  let data = await read(join(process.cwd(), 'pages', '_app.js'), 'utf-8')
  return {
    props: {
      data
    }
  }
}